import requests


class YunPian:
    def __init__(self, api_key):
        self.api_key = api_key

    def send_single_sms(self, phone, code):
        "发送单条短信"
        url = "https://sms.yunpian.com/v2/sms/single_send.json"
        text = "【转角的幸福】您的验证码是{}。如非本人操作，请忽略本短信".format(code)

        res = requests.post(url=url, data={
            'apikey': self.api_key,
            'mobile': phone,
            'text': text
        })

        return res.json()


if __name__ == '__main__':
    key = "ec336d122cd721ccfdec0de599d8dd57"
    yunpian = YunPian(key)
    res = yunpian.send_single_sms(17623603825, 1123)
    print(res)
